home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c++ / 194 < prev    next >
Encoding:
Text File  |  1996-08-06  |  3.0 KB  |  95 lines

  1. Path: fido.asd.sgi.com!austern
  2. From: Eugene Lazutkin <eugene@int.com>
  3. Newsgroups: comp.std.c++
  4. Subject: RE:  An STL helper -- and template and type shenanigans
  5. Date: 31 Jan 1996 12:04:06 PST
  6. Organization: -
  7. Approved: austern@isolde.mti.sgi.com
  8. Message-ID: <01BAEFD6.AD7E8620@dino.int.com>
  9. NNTP-Posting-Host: isolde.mti.sgi.com
  10. X-Original-Date: Wed, 31 Jan 1996 12:21:40 -0600
  11. Encoding: 73 TEXT
  12. X-Auth: PGPMoose V1.1 PGP comp.std.c++
  13.     iQBVAwUBMQ/LTEy4NqrwXLNJAQGbEwIAjtbc+0EEpF0ZdqT0geQ5wTtzLX2/X4Do
  14.     I7R/2LWIXQKXhrunvl7avesYs5jV1IyzvdBVh4PaAMCrvuAYOtYQYQ==
  15.     =XkBh
  16. Originator: austern@isolde.mti.sgi.com
  17.  
  18. On     Monday, January 29, 1996 12:50 PM,     fjh@munta.cs.mu.OZ.AU (Fergus Henderson) wrote:
  19. > esap@cs.tut.fi (Pulkkinen Esa) writes:
  20. > >template <class T>
  21. > >class type_dereferencer<T*>
  22. > >{
  23. > >public:
  24. > >  typedef T base_type;
  25. > >};
  26. > [...]
  27. > >And if typedef templates were allowed, you could use a slightly better
  28. > >syntax:
  29. > >
  30. > >template <class T>
  31. > >typedef type_dereferencer<T>::base_type type_dereference;
  32.  
  33. Don't forget another point: YOU CAN'T INHERIT CONSTRUCTORS.  In fact
  34.  
  35. 1) class B : public A {};
  36.  
  37. and
  38.  
  39. 2) typedef A B;
  40.  
  41. is not the same if you have non-default constructors in the class A. 
  42. You have to put some constructors in a 1st example, like
  43.  
  44. class B : public A 
  45. {
  46. public:
  47.     B( T1 x ) : A(x)    {}
  48.     B( T2 x ) : A(x)    {}
  49.     B( T1 x, T2 y ) : A(x,y)    {}
  50.     /* ... other constructors ... */
  51.     B() : A()    {}
  52.     B( const A& a ) : A(a) {}
  53. };
  54.  
  55. if you are going to emulate 2nd.  To me the typedef templates would solve 
  56. this problem easily and effectifely.
  57.  
  58. > Can someone please remind me why we decided not to allow typedef templates?
  59.  
  60. Yeah, why?
  61.  
  62. > It certainly seems like a bad idea to force everyone to use this silly
  63. > obfuscation for what is obviously a common need.
  64.  
  65. I wrote several wrappers like written above for my application which uses STL.
  66. When I change the set of possible constructors of the base class I need
  67. find all appropriate wrappers and correct them too.  I have to keep my code
  68. up-to-date manually.
  69.  
  70. Why do I use wrappers?  Just small example: vector< auto_ptr< T > > 
  71. (or list< auto_ptr< T > >).  I f you tried it, you'd discover that STL 
  72. (I use ObjectSpace's implementation) uses copy-ctor with a const parameter 
  73. and auto_ptr doesn't define it.  The same for a copy-op. Additionally  
  74. my VC++ 4.0 tries to instantiate some unused methods (?) and of course doesn't 
  75. find less-operator.  That's why I need wrappers.
  76.  
  77. BTW, how come that auto_ptr from Standard C++ Library is incompatible with
  78. vector<>, list<> and other STL containers from the same source? Or maybe I
  79. have incorrect implementation?
  80.  
  81. > Fergus Henderson                 WWW: http://www.cs.mu.oz.au/~fjh
  82. > fjh@cs.mu.oz.au                  PGP: finger fjh@128.250.37.3
  83.  
  84. Thanks in advance
  85.  
  86.  
  87.     
  88. Eugene Lazutkin
  89. eugene@int.com
  90. ---
  91. [ comp.std.c++ is moderated.  Submission address: std-c++@ncar.ucar.edu.
  92.   Contact address: std-c++-request@ncar.ucar.edu.  The moderation policy
  93.   is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]
  94.